package com.test.lotterysystem.Comment.Utils;

import com.test.lotterysystem.Comment.ErrorCode.ControllerErrorCode;
import com.test.lotterysystem.Comment.Exception.ControllerException;
import com.test.lotterysystem.Controller.Result.*;
import com.test.lotterysystem.Dao.DaoObject.PrizeDO;
import com.test.lotterysystem.Service.DTO.*;
import org.springframework.beans.BeanUtils;

public class MyBeanUtil {
    public static UserRegisterResult transOfUserRegisterResult(UserRegisterDTO userRegisterDTO) {
        if (userRegisterDTO == null) {
            throw new ControllerException(ControllerErrorCode.TRANS_ERROR);
        }
        UserRegisterResult userRegisterResult = new UserRegisterResult();
        BeanUtils.copyProperties(userRegisterDTO, userRegisterResult);
        return userRegisterResult;
    }

    public static UserLoginResult transOfUserLoginResult(UserLoginDTO userLoginDTO) {
        if (userLoginDTO == null) {
            throw new ControllerException(ControllerErrorCode.TRANS_ERROR);
        }
        UserLoginResult userLoginResult = new UserLoginResult();
        BeanUtils.copyProperties(userLoginDTO, userLoginResult);
        return userLoginResult;
    }

    public static UserInfo transOfUserInfo(UserInfoDTO userInfoDTO) {
        if (userInfoDTO == null) {
            throw new ControllerException(ControllerErrorCode.TRANS_ERROR);
        }
        UserInfo userInfo = new UserInfo();
        BeanUtils.copyProperties(userInfoDTO, userInfo);
        return userInfo;
    }

    public static PrizeDTO transOfPrizeDTO(PrizeDO prizeDO){
        if (prizeDO == null) {
            throw new ControllerException(ControllerErrorCode.TRANS_ERROR);
        }
        PrizeDTO prizeDTO = new PrizeDTO();
        prizeDTO.setPrizeId(prizeDO.getId());
        prizeDTO.setPrizeName(prizeDO.getName());
        prizeDTO.setDescription(prizeDO.getDescription());
        prizeDTO.setPrice(prizeDO.getPrice());
        prizeDTO.setImageUrl(prizeDO.getImageUrl());
        return prizeDTO;
    }

    public static ActivityCreateResult transOfActivityCreateResult(ActivityCreateDTO activityCreateDTO) {
        if (activityCreateDTO == null) {
            throw new ControllerException(ControllerErrorCode.TRANS_ERROR);
        }
        ActivityCreateResult activityCreateResult = new ActivityCreateResult();
        BeanUtils.copyProperties(activityCreateDTO,activityCreateResult);
        return activityCreateResult;
    }
}
